﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace MobileShop
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            siteMap.SetPath(((BasePage)this.Page).PageMap);
            if (!IsPostBack)
            {
                UpdateCart();
                RefreshLoginState();
            }
        }

        protected void lnkSearch_OnClick(object sender, EventArgs e)
        {
            Response.Redirect(this.ResolveUrl("~/Search.aspx?key=") + txtSearch.Text);
        }

        public void UpdateCart()
        {
            lblTotalItem.Text = string.Format(" {0} items", BasePage.TotalQuantity);
        }

        protected void lnkLogout_OnClick(object sender, EventArgs e)
        {
            View_Customers.SetCurrentUser(null);
            RefreshLoginState();
            Response.Redirect(Request.Url.PathAndQuery);
        }

        void RefreshLoginState()
        {
            lblUser.Text = View_Customers.GetCurrentUser() == null || View_Customers.GetCurrentUser().RowCount == 0 ? "Welcome, " : "Hello " + View_Customers.GetCurrentUser().s_CustomerName + ", ";
            lnkLogout.Visible = View_Customers.GetCurrentUser() == null || View_Customers.GetCurrentUser().RowCount == 0 ? false : true;
            lnkLogin.Visible = !lnkLogout.Visible;
        }
    }
}